package com.woniuxy01;

import java.util.Scanner;

/**
 * @author 作者
 * @create 2025-07-17 14:14
 */
public class Test11 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int userShowNum;
        String userShowName="";
        int computerShowNum;
        String computerShowName="";
        //记录对战次数,用户获胜次数，电脑获胜次数
        int count=0,userWin=0,computerWin=0;
        String answer="";

        do {
            count++;
            //用户出拳
            System.out.println("用户出拳：1.剪刀2.石头3.布");
            userShowNum = sc.nextInt();
            while (!(userShowNum == 1 || userShowNum == 2 || userShowNum == 3)) {
                System.out.println("输入错误，重新输入：1.剪刀2.石头3.布");
                userShowNum = sc.nextInt();
            }
            //显示用户出拳
            switch (userShowNum) {
                case 1:
                    userShowName = "剪刀";
                    break;
                case 2:
                    userShowName = "石头";
                    break;
                case 3:
                    userShowName = "布";
                    break;
            }
            System.out.println("用户出拳："+userShowName);
            //电脑出拳
            computerShowNum=((int)(Math.random()*1000))%3+1;
            //显示电脑出拳
            switch (computerShowNum) {
                case 1:
                    computerShowName = "剪刀";
                    break;
                case 2:
                    computerShowName = "石头";
                    break;
                case 3:
                    computerShowName = "布";
                    break;
            }
            System.out.println("电脑出拳："+computerShowName);
            //判断本局胜负
            if((userShowNum==1&&computerShowNum==3)||(userShowNum==2&&computerShowNum==1)||(userShowNum==3&&computerShowNum==2)){
                userWin++;
                System.out.println("本局用户获胜");
            }else if(userShowNum==computerShowNum){
                System.out.println("本局平局");
            }else{
                computerWin++;
                System.out.println("本局电脑获胜");
            }
            System.out.println("是否继续下一局y/n");
            answer = sc.next();
        } while ("y".equals(answer));
        //统计最终结果
        if(userWin>computerWin){
            System.out.println("最终结果：用户获胜");
        }else if(userWin==computerWin){
            System.out.println("最终结果：平局");
        }else{
            System.out.println("最终结果：电脑获胜");
        }
    }
}
